﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="/demo/css/bootstrap.min.css" rel="stylesheet" />
    <link href="/demo/css/ResultQueryCss.css" rel="stylesheet" />
    <link href="/demo/css/styles.css" rel="stylesheet" />
    <script src="/demo/js/jquery-1.11.3.min.js"></script>
    <script src="/demo/js/bootstrap.min.js"></script>
    <script src="demo/js/sha.js"></script>
    <script src="demo/js/json2.js"></script>
    <script src="demo/js/jquery.md5.js"></script>
    <script src="demo/js/httphelp.js"></script>
    <!--对话框js-->
    <script src="/demo/js/main.js"></script>


    <title>测试页面</title>
</head>
<body style="background-color: #efefef;">


    <div id="wrapper" style="padding: 10px;margin-bottom: 50px;width:100%;background-color: #efefef;">
        <img id="valiCode" style="cursor: pointer;" src="/FluentCaptcha/FluentCaptcha" alt="验证码" />  
        <center>
            <table width="95%" id="submittable">
                <tr>
                    <td width="30%"><span class="star"></span><span class="text">栏目名：</span></td>
                    <td width="70%" colspan="2"><input id="name" type="text" class="form-control" style="width: 95%;height: 35px;"></td>
                </tr>
                <tr>
                    <td width="30%"><span class="star"></span><span class="text">栏目备注：</span></td>
                    <td width="70%" colspan="2"><input id="pwd" type="text" class="form-control" style="width: 95%;height: 35px;"></td>
                </tr>
                <tr>
                    <td width="30%"><span class="star"></span><span class="text">用户名：</span></td>
                    <td width="70%" colspan="2"><input id="username" type="text" class="form-control" style="width: 95%;height: 35px;"></td>
                </tr>
            </table>
        </center>
        <div>
            <div style="float: left;height: 60px;line-height: 60px;text-align: center;width: 50%;">
                <button class="mybtn1" id="adduser" >添加账户</button>
            </div>
            <div style="float: right;height: 60px;line-height: 60px;text-align: center;width: 50%;">
                <button class="mybtn" id="add">添加</button>
            </div>

            <div style="float: right;height: 60px;line-height: 60px;text-align: center;width: 50%;">
                <button class="mybtn1" id="addInfo">添加信息文章</button>
            </div>

            <div style="float: right;height: 60px;line-height: 60px;text-align: center;width: 50%;">
                <button class="mybtn1" id="post">信息添加文章</button>
            </div>
        </div>
       
      



    </div>
   
   <script>
       $(function () {

           $("#adduser").click(function () {
               $.ajax({
                   type: "GET",
                   url: "api/Users/AddAccount?Account=" + $("#name").val() + "&Pwd=" + $("#pwd").val() + "&UserName=" + $("#username").val(),
                   success: function (result) {
                       if (result.code == 0) {
                           alert(result.message);

                       }
                       else {
                           alert(result.message);
                       }
                   },
                   error: function (result) {
                       var r = eval('(' + result.responseText + ')');
                       if (r.code == 0) {
                           alert(r.message );

                       }
                       else {
                           alert( r.message);
                       }
                   }
               });
           });

           $("#add").click(function () {
               var content = {
                   "ColumnName": $("#name").val(),
                   "Remark": $("#pwd").val()
               }
               $.ajax({
                   type: "POST",
                   url: "/api/InfoList/AddInfoColumn",
                   data:content,
                   success: function (result) {
                       if (result.code == 0) {                         
                           alert(result.message);
                       }
                       else {
                           alert(result.message);
                       }
                   },
                   error: function (result) {
                       var r = eval('(' + result.responseText + ')');
                       if (r.code == 0) {
                           alert(r.message);
                       }
                       else {
                           alert(r.message);
                       }
                   }
               });
           });

           $("#addInfo").click(function () {
               var url = "api/InfoArticle/AddInfoArticle";
               var HttpMethod="POST";
               var content = {
                   "Title": $("#name").val(),
                   "Content": $("#pwd").val(),
                   "IsPublish": true
               }
               $.ajax({
                   type: HttpMethod,
                   url: url,
                   data:content,
                   success: function (result) {
                       if (result.code == 0) {
                           alert(result.message);
                       }
                       else {
                           alert(result.message);
                       }
                   },
                   error: function (result) {
                       var r = eval('(' + result.responseText + ')');
                       alert(r.message);
                   }
               });
           });

           $("#post2").click(function () {
               var timestamp = Date.parse(new Date()) / 1000;
               var nonce = randomString(8);
               var token = $("#add").data("token");
               var url = "http://localhost:47503/api/Customer/AddCustomerInfo";
               var HttpMethod = "POST";
               var content = {
                   "ID": "sample string 1",
                   "UserName": "sample string 2",
                   "Email": "sample string 3",
                   "Phone": "sample string 4",
                   "Fax": "sample string 5",
                   "QQ": "sample string 6",
                   "RealUserName": "sample string 7",
                   "Career": "sample string 8",
                   "CompanyName": "sample string 9",
                   "EnterpriseLegalPerson": "sample string 10",
                   "CompanyAddress": "sample string 11",
                   "AgentID": "sample string 12",
                   "SysCreatedBy": "sample string 13",
                   "SysCreate": "2016-07-13 05:30:12",
                   "SysLastUpdBy": "sample string 14",
                   "SysLastUpd": "2016-07-13 05:30:12",
                   "SysDeleted": true
               }
               var incomingBase64Signature = getincomingBase64Signature(appid, HttpMethod, url, token, nonce, timestamp, content);
               $.ajax({
                   type: HttpMethod,
                   url: url,
                   data:content,
                   beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'amx ' + appid + ":" + incomingBase64Signature + ":" + token + ":" + nonce + ":" + timestamp); },
                   success: function (result) {

                       if (result.code == 0) {
                           alert(JSON.stringify(result.data));
                       }
                       else {
                           alert(result.message);
                       }
                   },
                   error: function (result) {
                       var r = eval('(' + result.responseText + ')');
                       alert(r.message);
                   }
               });
           });



           $("#post").click(function () {
               var url = "/api/InfoArticle/AddInfoArticleForInfo";
               var HttpMethod = "POST";
               var content = {
                   "CID": "sample string 1",
                   "PicUrl": "sample string 2",
                   "Hot": 3,
                   "Title": "sample string 4",
                   "Content": "sample string 5",
                   "IsPublish": true
               }
               //var headerStr = $.GetHeaderStr2(HttpMethod, url,content);
               $.ajax({
                   type: HttpMethod,
                   url: url,
                   data: content,
                   //beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', headerStr); },
                   //headers: {
                   //    'Authorization': $.httphelp.GetHeaderStr(HttpMethod, url, content)
                   //},
                   success: function (result) {
                       alert(result.message);
                   },
                   error: function (result) {
                       var r = eval('(' + result.responseText + ')');
                       alert(r.message);
                   }
               });
           });
       });

       

   </script>
</body>
</html>
